package common.util 
{
	import flash.geom.Point;
	import ui.data.MapInfo;
	/**
	 * ...
	 * @author Surui
	 */
	public class MapBoxUtil 
	{
		
		public function MapBoxUtil() 
		{
			
		}
		
		/**
		 * 根据格子坐标获取实际坐标
		 * @param	c
		 * @param	r
		 * @return
		 */
		public static function getRealPoint( c:int, r:int ):Point {
			var x:Number = (c - r) * MapInfo.self.unitWidht;
			var y:Number = (c + r) * MapInfo.self.unitHeight;
			return new Point(x, y);
		}
		/**
		 * 根据真实坐标获取Box坐标
		 * @param	real
		 * @return
		 */
		public static function getBoxPoint( real:Point ):Point {
			real.y = real.y + MapInfo.self.unitHeight;
			var a_point0:Point = real.clone();
			var a_point1:Point = real.clone().add(MapInfo.self.yAxes);
			var b_point0:Point = new Point(0, 0);
			var b_point1:Point = MapInfo.self.xAxes.clone();
			
			var crossPoint:Point = Vector2DUtil.getCrossPoint(a_point0, a_point1, b_point0, b_point1 );
			trace(crossPoint.x,crossPoint.y);
			var c:int = (crossPoint.x > 0?1: -1) * crossPoint.length / MapInfo.self.xAxes.length;
			var r:int = (crossPoint.y > 0?1: -1) * (a_point1.subtract(crossPoint).length / MapInfo.self.yAxes.length - 1);
			trace(c,r);
			return new Point(c, r);
		}
		/**
		 * 根据真实坐标,获取Box的中心真实坐标
		 * @param	real
		 * @return
		 */
		public static function getBoxCenterPoint( real:Point ):Point {
			var boxPoint:Point = getBoxPoint( real );
			return getRealPoint( boxPoint.x, boxPoint.y );
		}
	}

}